public class StringQuestion {
    public int strWordCount(String s){
        int count = 0;
        for (int i = 0; i < s.length()-1; i++) {
            char ret = s.charAt(i);
            if(Character.isLetterOrDigit(ret)){
                count++;
            }
        }
        return count;
    }
    public int firstUniqChar(String s){
        //将一个数组中第一个没有重复出现的字符的下标输出
        int[] count = new int[26];
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            count[ch-'a']++;
        }
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if(count[ch-'a']==1){
                return i;
            }
        }
        return -1;
    }

    public int lastWordlen(String s){
        //找到最后一个单词的长度
        //1.
        //int pos = 0;
        //for (int i = s.length()-1; i >=0 ; i--) {
        //    if(s.charAt(i)==' '){
        //        pos=i;
        //        break;
        //    }
        //}
        //return (s.length()-1-pos);
        //2.
        int posi = 0;
        posi = s.lastIndexOf(" ");
        return (s.length()-1-posi);

    }

    //回文串判定
    public boolean isEffective(char ch){
        if(Character.isDigit(ch)||Character.isLetter(ch)){
            return true;
        }
        return false;

        //return Character.isLetterOrDigit(ch);//判断是不是字母或数字
    }

    public boolean isPalindrome(String s){
        s = s.toLowerCase();//全部转小写
        int left = 0;
        int right = s.length()-1;
        while(left<right){
            //char ch = s.charAt(left);
            while(left<right && !isEffective(s.charAt(left))){
                left++;
            }
            //此时的left下标处一定是有效字符
            while(left<right && !isEffective(s.charAt(right))){
                right--;
            }
            //此时right一定是有效字符
            if(s.charAt(left) != s.charAt(right)){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {

    }
}
